package my2Cents.properties;

import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.KeyAdapter;

import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class Description extends Property {
	private static final long serialVersionUID = 1L;
	private JTextArea desc;
	private JScrollPane sp;
	private Font f = new Font("Arial", Font.PLAIN, 10);
	
	public Description(String string) {
		this.setSize(10,60);
		desc = new JTextArea();
		desc.setText(string);
		desc.setEditable(false);
		desc.setFont(f);
		desc.setBackground(bgColor);
		sp = new JScrollPane(desc);
		sp.setBorder(null);
		sp.setHorizontalScrollBarPolicy(
			JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
		add(sp);
	}
	
	public void setCloseKeyAdapter(KeyAdapter ka) {
		super.setCloseKeyAdapter(ka);
		desc.addKeyListener(getCloseKeyAdapter());
	}
	
	public void validate() {
		super.validate();
		if(getParent() != null) {
			int w = getParent().getWidth();
			this.setSize(w,80);
			sp.setLocation(3,3);
			sp.setSize(getWidth()-6,getHeight()-6);
			sp.setPreferredSize(desc.getSize());
		}
	}
	
	public void setDescription(String txt) {
		desc.setText(txt);
	}

	public String getDescription() {
		return desc.getText();
	}
}
